import { assetTypeMap, diskTypeMap, envMap, zoneMap } from '@/views/cmdb/config'
import { Tag } from 'view-design'

export const assetColumns = _this => [
  {
    title: 'IP地址',
    key: 'business_ip',
    sortable: true,
    render: (h, { row }) => {
      return <router-link to={'/cmdb/asset/' + row.id} style='color: #2d8cf0'>{row.businessIp}</router-link>
    }
  },
  {
    title: '主机名',
    key: 'hostname',
    width: 150,
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.hostname}</span>
    }
  },
  {
    title: '资产类型',
    key: 'asset_type',
    width: 120,
    sortable: true,
    render: (h, { row }) => {
      return <Tag color={assetTypeMap[row.assetType].color}>{assetTypeMap[row.assetType].name}</Tag>
    }
  },
  {
    title: 'CPU(核)',
    key: 'cpu',
    width: 80,
    sortable: true,
    render: (h, { row }) => {
      if (row.cpu) {
        return <span>{row.cpu}</span>
      } else {
        return <span>-</span>
      }
    }
  },
  {
    title: '内存(G)',
    key: 'memory',
    width: 80,
    sortable: true,
    render: (h, { row }) => {
      if (row.memory) {
        return <span>{row.memory
        }</span>
      } else {
        return <span>-</span>
      }
    }
  },
  {
    title: '硬盘(T)',
    key: 'disk',
    width: 80,
    sortable: true,
    render: (h, { row }) => {
      if (row.diskType && row.diskSize) {
        return <span>{diskTypeMap[row.diskType].name}:{row.diskSize}T</span>
      } else {
        return <span>-</span>
      }
    }
  },
  {
    title: '环境',
    key: 'env',
    width: 100,
    sortable: true,
    render: (h, { row }) => {
      return <Tag color={envMap[row.env].color}>{envMap[row.env].name}</Tag>
    }
  },
  {
    title: '区域',
    key: 'zone',
    width: 100,
    sortable: true,
    render: (h, { row }) => {
      return <Tag color={zoneMap[row.zone].color}>{zoneMap[row.zone].name}</Tag>
    }
  },
  {
    title: '创建时间',
    key: 'create_time',
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.createTime}</span>
    }
  },
  {
    title: '更新时间',
    key: 'update_time',
    sortable: true,
    render: (h, { row }) => {
      return <span>{row.updateTime}</span>
    }
  },
  {
    title: '操作',
    key: 'operate',
    render: (h, { row }) => {
      return <div>
        <el-tooltip className='item' effect='dark' content='修改' placement='top-end'>
          <el-link
            underline={false}
            vOn:click={() => {
              _this.showAssetActionModal = true
              _this.assetInfo = row
              _this.action.type = 'update'
              _this.action.title = '更新'
            }} size='small' type='primary'>修改
          </el-link>
        </el-tooltip>
        <el-divider direction='vertical' />
        <el-tooltip className='item' effect='dark' content='删除' placement='top-end'>
          <el-link
            underline={false}
            vOn:click={() => {
              _this.showAssetDeleteModal = true
              _this.assetInfo = row
            }} size='small' style='font-size:13px;' type='danger'>删除
          </el-link>
        </el-tooltip>
      </div>
    }
  }
]
